package main

import (
	"fmt"
	"time"
)

func main() {
	p := make(chan int, 10)
	for i := 0; i < 3; i++ {
		go func(n int) {
			for {
				v := <-p
				stNow := time.Now()
				strNow := stNow.Format("2006-01-02 15:04:05")
				fmt.Printf("%s goroutine %d received %d\n", strNow, n, v)
			}
		}(i)
	}
	go func() {
		n := 0
		for {
			p <- n
			n++
			p <- n
			n++
			p <- n
			n++
			p <- n
			n++
			time.Sleep(1 * time.Second)
			fmt.Println("---------------------")
		}
	}()
	fmt.Println("Goroutine ...~~")
	time.Sleep(60 * time.Second)
	fmt.Println("Goroutine end.~~")
}
